package com.joven.interface3.config;

import com.joven.interface3.webservice.CommonService;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * @author joven_wong
 * 2021/6/25 15:47
 */
@Configuration
public class CxfConfig {

//    @Bean(name = Bus.DEFAULT_BUS_ID)
//    public SpringBus springBus() {
//        return new SpringBus();
//    }
    @Autowired
    Bus bus;

    @Autowired
    CommonService commonService;

    /**
     * 此方法被注释后:wsdl访问地址为http://127.0.0.1:8085/services/jovenWebservice?wsdl
     * 去掉注释后：wsdl访问地址为：http://127.0.0.1:8085/soap/jovenWebservice?wsdl
     */
    //改用配置文件
//    @Bean
//    public ServletRegistrationBean dispatcherServlet(){
//        return new ServletRegistrationBean(new CXFServlet(),"/soap/*");
//    }

    //发布服务，指定url
    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(bus, commonService);
        endpoint.publish("/jovenWebservice");
        return endpoint;
    }

}
